package com.victor.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.victor.dao.CollectionfolderDao;
import com.victor.entity.collection.CollectionFolder;
import com.victor.service.CollectionfolderService;
@Service
public class CollectionfolderServiceImpl implements CollectionfolderService {
	@Autowired
	private CollectionfolderDao dao;

	@Override
	public boolean insertCollectionFolder(CollectionFolder collectionFolder) {
		return dao.insertCollectionFolder(collectionFolder);
	}

	@Override
	public boolean delCollectionFolder(int[] ids) {
		return dao.delCollectionFolder(ids);
	}

	@Override
	public PageInfo<CollectionFolder> selAllFolder(String uid, int page, int row) {
		PageHelper.startPage(page, row);
		List<CollectionFolder> list = dao.selAllFolder(uid);
		if (list != null) {
			for (int i = 0; i < list.size(); i++) {
				if (list.get(i).getCollections() != null) {
					for (int j = 0; j < list.get(i).getCollections().size(); j++) {
						Map<Object, Object> selByTablenameAndPid = dao.selByTablenameAndPid(list.get(i).getCollections().get(j).getPid(),list.get(i).getCollections().get(j).getTable_name());
						list.get(i).getCollections().get(j).setMap(selByTablenameAndPid);
					}
				}
			}
		}
		return new PageInfo<>(list, 5);
	}

	@Override
	public boolean updateFolder(CollectionFolder folder) {
		return dao.updateFolder(folder);
	}

}
